home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / pdftops / xpdf / h / Link < prev    next >
Text File  |  1996-06-08  |  5KB  |  212 lines

  1. //========================================================================
  2. //
  3. // Link.h
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifndef LINK_H
  10. #define LINK_H
  11.  
  12. #ifdef __GNUC__
  13. //#pragma interface
  14. #endif
  15.  
  16. #include "Object.h"
  17.  
  18. class GString;
  19. class Array;
  20. class Dict;
  21. class Catalog;
  22.  
  23. //------------------------------------------------------------------------
  24. // LinkAction
  25. //------------------------------------------------------------------------
  26.  
  27. enum LinkActionKind {
  28.   actionGoto,            // GoTo and GoToR
  29.   actionURI,            // URI
  30.   actionUnknown            // anything else
  31. };
  32.  
  33. class LinkAction {
  34. public:
  35.  
  36.   // Destructor.
  37.   virtual ~LinkAction() {}
  38.  
  39.   // Was the LinkAction created successfully?
  40.   virtual GBool isOk() = 0;
  41.  
  42.   // Check link action type.
  43.   virtual LinkActionKind getKind() = 0;
  44. };
  45.  
  46.  
  47. //------------------------------------------------------------------------
  48. // LinkGoto
  49. //------------------------------------------------------------------------
  50.  
  51. enum LinkGotoKind {
  52.   gotoXYZ,
  53.   gotoFit,
  54.   gotoFitH,
  55.   gotoFitV,
  56.   gotoFitR,
  57.   gotoFitB,
  58.   gotoFitBH,
  59.   gotoFitBV
  60. };
  61.  
  62. class LinkGoto: public LinkAction {
  63. public:
  64.  
  65.   // Build a LinkGoto from the array.
  66.   LinkGoto(Array *a, Catalog *catalog);
  67.  
  68.   // Build a remote LinkGoto from the file name and array.
  69.   LinkGoto(GString *fileName1, Array *a, Catalog *catalog);
  70.  
  71.   // Build a remote LinkGoto from the file specification and array.
  72.   LinkGoto(Dict *fileSpec, Array *a, Catalog *catalog);
  73.  
  74.   // Destructor.
  75.   virtual ~LinkGoto();
  76.  
  77.   // Was the LinkGoto created successfully?
  78.   virtual GBool isOk() { return ok; }
  79.  
  80.   // Accessors.
  81.   virtual LinkActionKind getKind() { return actionGoto; }
  82.   GBool isRemote() { return remote; }
  83.   GString *getFileName() { return fileName; }
  84.   LinkGotoKind getDestKind() { return kind; }
  85.   int getPageNum() { return pageNum; }
  86.   double getLeft() { return left; }
  87.   double getBottom() { return bottom; }
  88.   double getRight() { return right; }
  89.   double getTop() { return top; }
  90.   double getZoom() { return zoom; }
  91.   GBool getChangeLeft() { return changeLeft; }
  92.   GBool getChangeTop() { return changeTop; }
  93.   GBool getChangeZoom() { return changeZoom; }
  94.  
  95. private:
  96.  
  97.   GBool getPosition(Array *a, Catalog *catalog);
  98.  
  99.   GBool remote;            // true if link refers to a different file
  100.   GString *fileName;        // remote file name
  101.   LinkGotoKind kind;        // destination type
  102.   int pageNum;            // destination page number
  103.   double left, bottom;        // destination position
  104.   double right, top;
  105.   double zoom;            // destination zoom factor
  106.   GBool changeLeft, changeTop;    // for destXYZ links, which position
  107.   GBool changeZoom;        //   components to change
  108.   GBool ok;            // set if created successfully
  109. };
  110.  
  111. //------------------------------------------------------------------------
  112. // LinkURI
  113. //------------------------------------------------------------------------
  114.  
  115. class LinkURI: public LinkAction {
  116. public:
  117.  
  118.   // Build a LinkURI given the URI.
  119.   LinkURI(GString *uri1);
  120.  
  121.   // Destructor.
  122.   virtual ~LinkURI();
  123.  
  124.   // Was the LinkURI created successfully?
  125.   virtual GBool isOk() { return gTrue; }
  126.  
  127.   // Accessors.
  128.   virtual LinkActionKind getKind() { return actionURI; }
  129.   GString *getURI() { return uri; }
  130.  
  131. private:
  132.  
  133.   GString *uri;            // the URI
  134. };
  135.  
  136. //------------------------------------------------------------------------
  137. // LinkUnknown
  138. //------------------------------------------------------------------------
  139.  
  140. class LinkUnknown: public LinkAction {
  141. public:
  142.  
  143.   // Build a LinkUnknown given the action subtype.
  144.   LinkUnknown(char *action1);
  145.  
  146.   // Destructor.
  147.   virtual ~LinkUnknown();
  148.  
  149.   // Was the LinkUnknown create successfully?
  150.   virtual GBool isOk() { return gTrue; }
  151.  
  152.   // Accessors.
  153.   virtual LinkActionKind getKind() { return actionUnknown; }
  154.   GString *getAction() { return action; }
  155.  
  156. private:
  157.  
  158.   GString *action;        // action subtype
  159. };
  160.  
  161. //------------------------------------------------------------------------
  162. // Link
  163. //------------------------------------------------------------------------
  164.  
  165. class Link {
  166. public:
  167.  
  168.   // Construct a link, given its dictionary.
  169.   Link(Dict *dict, Catalog *catalog);
  170.  
  171.   // Destructor.
  172.   ~Link();
  173.  
  174.   // Check if point is inside the link rectangle.
  175.   GBool inRect(int x, int y)
  176.     { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
  177.  
  178.   // Get action.
  179.   LinkAction *getAction() { return action; }
  180.  
  181. private:
  182.  
  183.   int x1, y1;            // lower left corner
  184.   int x2, y2;            // upper right corner
  185.   double borderW;        // border width
  186.   LinkAction *action;        // action
  187. };
  188.  
  189. //------------------------------------------------------------------------
  190. // Links
  191. //------------------------------------------------------------------------
  192.  
  193. class Links {
  194. public:
  195.  
  196.   // Extract links from array of annotations.
  197.   Links(Object *annots, Catalog *catalog);
  198.  
  199.   // Destructor.
  200.   ~Links();
  201.  
  202.   // If point <x>,<y> is in a link, return the link; else return NULL.
  203.   Link *find(int x, int y);
  204.  
  205. private:
  206.  
  207.   Link **links;
  208.   int numLinks;
  209. };
  210.  
  211. #endif
  212.